﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace GPSTrackingWebsiteManager.Manager.UserControls
{
    public partial class ToolBarGeneric : System.Web.UI.UserControl
    {
        //Propeties
        [Browsable(true), Category("Custom"), DefaultValue(true)]
        public bool NewItemVisible { get; set; }

        [Browsable(true), Category("Custom"), DefaultValue(true)]
        public bool SaveItemVistible { get; set; }

        [Browsable(true), Category("Custom"), DefaultValue(true)]
        public bool DeleteItemVistible { get; set; }


        //Events
        public delegate void NewItemEvent();
        public event NewItemEvent OnNewItemPressed;

        public delegate void SaveItemEvent();
        public event SaveItemEvent OnSaveItemPressed;

        public delegate void DeleteItemEvent();
        public event DeleteItemEvent OnDeleteItemPressed;




        protected void Page_Load(object sender, EventArgs e)
        {
            tbgToolBarGeneric.Items[0].Visible = NewItemVisible;
            tbgToolBarGeneric.Items[1].Visible = SaveItemVistible;
            tbgToolBarGeneric.Items[2].Visible = DeleteItemVistible;

        }

        protected void tbgToolBarGeneric_ButtonClick(object sender, Telerik.Web.UI.RadToolBarEventArgs e)
        {
            try
            {
                switch (e.Item.Text)
                {
                    case "Nuevo": OnNewItemPressed(); break;
                    case "Guardar": OnSaveItemPressed(); break;
                    case "Eliminar": OnDeleteItemPressed(); break;
                    default: break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}